package com.woniuxy.platform.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.platform.client.PersonalServiceFeignClient;
import com.woniuxy.platform.core.constant.PromotionConstant;
import com.woniuxy.platform.core.mapper.PmComplainMapper;
import com.woniuxy.platform.core.model.PmComplain;
import com.woniuxy.platform.core.service.PmComplainService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-07-08
 */
@Service
public class PmComplainServiceImpl extends ServiceImpl<PmComplainMapper, PmComplain> implements PmComplainService {

    @Resource
    private PmComplainMapper complainMapper;

    @Resource
    private PersonalServiceFeignClient client;

    @Override
    public List<PmComplain> selectComplain() {
        /*List<PmComplain> list = this.complainMapper.selectComplain();
        for (PmComplain complain : list) {
            String orderNumber = complain.getOrderNumber();
            if (orderNumber == null){
                complain.setOrderNumber(this.client.selectOrderNumber(complain.getId()));
                this.complainMapper.updateById(complain);
            }

        }*/
        List<PmComplain> list = this.complainMapper.selectComplain();
        for (PmComplain complain : list) {
            if (complain.getStatus() == PromotionConstant.STATUS_NO){
                complain.setStatusChina(PromotionConstant.STATUS_NO_CHINA);
                this.complainMapper.updateById(complain);
            }
            if (complain.getStatus() == PromotionConstant.STATUS_OVER){
                complain.setStatusChina(PromotionConstant.STATUS_OVER_CHINA);
                this.complainMapper.updateById(complain);
            }

        }
        return list;
    }

    @Override
    public List<PmComplain> selectMH(PmComplain pmComplain) {
        List<PmComplain> list = this.complainMapper.selectMH(pmComplain);
        for (PmComplain pmComplain1 :list) {
            if (pmComplain1.getStatus() == PromotionConstant.STATUS_NO){
                pmComplain1.setStatusChina(PromotionConstant.STATUS_NO_CHINA);
                this.complainMapper.updateById(pmComplain1);
            }
            if (pmComplain1.getStatus() == PromotionConstant.STATUS_OVER){
                pmComplain1.setStatusChina(PromotionConstant.STATUS_OVER_CHINA);
                this.complainMapper.updateById(pmComplain1);
            }
        }
        return list;
    }

    @Override
    public int updateDispose(PmComplain pmComplain) {
        pmComplain.setStatus(PromotionConstant.STATUS_OVER);
        int i = this.complainMapper.updateById(pmComplain);
        return i;
    }

    @Override
    public int insertComplain(PmComplain pmComplain) {
        pmComplain.setCreatetime(new Date());
        int i = this.complainMapper.insert(pmComplain);
        return i;
    }

    @Override
    public int selectComplainCount(Integer storeId) {
        return complainMapper.selectComplainCount(storeId);
    }
}
